
import { setToken, getToken } from '@/utils/auth'
import { login, getinfo } from '@/api/user'
const state = {
  token: getToken() || '',
  getdata: {}
}
const mutations = {
  setToken(state, newToken) {
    state.token = newToken
    setToken(newToken)
  },

  getinfo(state, newToken) {
    state.getdata = newToken
  }
}

const actions = {
  // 获取信息业务
  logout(context) {
    context.commit('getinfo', '')
    context.commit('setToken', '')
  },
  async getuserinfo(context) {
    // const sj = { name: '测试' }
    const res = await getinfo()
    console.log(res)
    context.commit('getinfo', res.data)
    return res.data
  },
  // 登录业务
  async  login(context, payload) {
    // console.log(context, payload)
    const res = await login(payload)
    console.log(res)
    const token = res.data

    context.commit('setToken', token)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}

